package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.common.base.model.CooperationCompanyUser;
import com.newtouch.bxzs.common.base.model.User;
import com.newtouch.bxzs.database.synchronize.batch.process.ProcesorSystemUser;
import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderData;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriterSystemUser;
import com.newtouch.bxzs.database.synchronize.model.UserBO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户同步step
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 11:00</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class SystemUserStep {

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderData readerData;

    @Autowired
    private WriterSystemUser writerSystemUser;

    @Autowired
    private ProcesorSystemUser procesorSystemUser;

    /**批处理本端用户数据*/
    public Step bankUserStep(){
        return stepBuilderFactory.get("bankUserStep")
                .<UserBO, User>chunk(100)
                .reader(readerData.getOwnUser())
                .writer(writerSystemUser.addOwnSystemUser())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(100)
                .build();
    }

    /**批处理同步对端用户数据*/
    public Step insuranceUser(){
        return stepBuilderFactory.get("insuranceUser")
                .<UserBO, CooperationCompanyUser>chunk(100)
                .reader(readerData.getOppositeUserOther())
                .processor(procesorSystemUser.processorCooperationUser())
                .writer(writerSystemUser.addOppositeSystemUser())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(100)
                .build();
    }
}
